package com.eqdd.yiqidian.ui.mine.wo;

/**
 * @author吕志豪 .
 * @date 17-10-31  下午4:54.
 * Github :https://github.com/lvzhihao100
 * E-Mail：1030753080@qq.com
 * 简书 :http://www.jianshu.com/u/6e525b929aac
 */

import android.media.MediaPlayer;
import android.util.Log;

import java.io.File;

public class UPlayer implements IVoiceManager {

    private final String TAG = UPlayer.class.getName();
    private String path;

    private MediaPlayer mPlayer;

    public UPlayer(String path) {
        this.path = path;
        mPlayer = new MediaPlayer();
    }

    @Override
    public boolean start() {
        try {
            //设置要播放的文件
            mPlayer.setDataSource(path);
            mPlayer.prepare();
            //播放
            mPlayer.start();
        } catch (Exception e) {
            Log.e(TAG, "prepare() failed");
        }

        return false;
    }

    @Override
    public boolean stop() {
        mPlayer.stop();
        mPlayer.release();
        mPlayer = null;
        return false;
    }

    public String getInfo() {
        try {
            //设置要播放的文件
            mPlayer.setDataSource(path);
            mPlayer.prepare();
            int duration = mPlayer.getDuration()/1000000;
            long totalSpace = new File(path).getTotalSpace() / (1024 * 1024);
            return "时长:" + duration + "大小" + totalSpace;
        } catch (Exception e) {
            System.out.println(e);
            Log.e(TAG, "prepare() failed");
        }
        return "12";
    }
}